package cn.alex.springaidemo;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 聊天客户端
 *
 * @author Alex
 * @date 2024/9/19 23:41
 */
@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class ChatClientController {
    private final ChatClient chatClient;

    @GetMapping("/client")
    public String completion(@RequestParam(value = "msg", defaultValue = "你是谁？") String msg) {
        return chatClient.prompt()
                // 用户输入
                .user(msg)
                // 请求模型
                .call()
                // 返回内容
                .content();
    }
}
